
package com.qgs.waf.controller.zbks;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qgs.waf.service.ZbksAttackSummaryService;

/**
 * @show 受攻击汇总
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "/zbks/as")
public class ZbksAttackSummaryController {
	private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd");

	@Autowired
	private ZbksAttackSummaryService zs;

	/**
	 * @show 获取省份列表和行业列表
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "provinceandindustroy", produces = "application/json; charset=utf-8")
	public String provinceandindustroy(@RequestParam(value = "start", required = false, defaultValue = "0") long start, @RequestParam(value = "end", required = false, defaultValue = "100") int end) {
		return zs.getProvinceAndInDustroy();
	}

	/**
	 * @show 获取设备列表
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "device", produces = "application/json; charset=utf-8")
	public String device() {
		return zs.getDevices();
	}

	/**
	 * @show 监控监测 受攻击汇总 拦截攻击前10客户 (返回的是客户的统计数据) 1.监控监测 受攻击汇总 拦截攻击前10客户
	 *       (返回的是客户的统计数据) 地址:/as/sgjhz/list 参数: { size:10, start:'2015-1-1',
	 *       end:'2015-1-1', province:'xx', industry:'xx' }
	 * @param size
	 *            int 返回条数,默认为10
	 * @param start
	 *            java.util.Date 开始时间
	 * @param end
	 *            java.util.Date 结束时间
	 * @param province
	 *            String 省份
	 * @param industry
	 *            String 行业
	 * @return
	 * @throws ParseException
	 */
	@ResponseBody
	@RequestMapping(value = "sgjhz/list", produces = "application/json; charset=utf-8")
	public String list(@RequestParam(value = "pn", required = false, defaultValue = "1") int pn,
			@RequestParam(value = "ps", required = false, defaultValue = "10") int ps,
			@RequestParam(value = "size", required = false, defaultValue = "10") int size, 
			@RequestParam(value = "start") @DateTimeFormat(pattern = "yyyy-MM-dd") Date start, 
			@RequestParam(value = "end") @DateTimeFormat(pattern = "yyyy-MM-dd") Date end, 
			@RequestParam(value = "province", required = false) String province, 
			@RequestParam(value = "industry", required = false) String industry) throws ParseException {
		return zs.queryCustomerSattackByProvinceAndIndustry(pn, ps, SDF.format(start), SDF.format(end), province, industry,null);
	}

	/**
	 * 2.监控监测 受攻击汇总 按省份统计饼图 地址:/as/sgjhz/pie/province 参数:{ size:10,
	 * start:'2015-1-1', end:'2015-1-1', province:'xx', industry:'xx' } 返回: [ {
	 * "name":'xxx', "score":123 }, { "name":'xxx', "score":123 } ]
	 * 
	 * @param pn
	 * @param ps
	 * @param start
	 * @param end
	 * @param province
	 * @return
	 * @throws ParseException
	 */
	@ResponseBody
	@RequestMapping(value = "sgjhz/pie/province", produces = "application/json; charset=utf-8")
	public String province(@RequestParam(value = "pn", required = false, defaultValue = "1") int pn, @RequestParam(value = "ps", required = false, defaultValue = "10000") int ps, @RequestParam(value = "start") @DateTimeFormat(pattern = "yyyy-MM-dd") Date start, @RequestParam(value = "end") @DateTimeFormat(pattern = "yyyy-MM-dd") Date end, @RequestParam(value = "province", required = false) String province) throws ParseException {
		return zs.queryCustomerSattackByProvinceAndIndustry(pn, ps, SDF.format(start), SDF.format(end), province, null,"province");
	}

	/**
	 * 3.监控监测 受攻击汇总 按行业统计饼图 地址:/as/sgjhz/pie/industry 参数:{ size:10,
	 * start:'2015-1-1', end:'2015-1-1', province:'xx', industry:'xx' }
	 * 
	 * 返回: [ { "name":'xxx', "score":123 }, { "name":'xxx', "score":123 } ]
	 * 
	 * @param pn
	 * @param ps
	 * @param size
	 * @param start
	 * @param end
	 * @param industry
	 * @return
	 * @throws ParseException
	 */
	@ResponseBody
	@RequestMapping(value = "sgjhz/pie/industry", produces = "application/json; charset=utf-8")
	public String industry(@RequestParam(value = "pn", required = false, defaultValue = "1") int pn, @RequestParam(value = "ps", required = false, defaultValue = "10000") int ps, @RequestParam(value = "size", required = false, defaultValue = "10") int size, @RequestParam(value = "start") @DateTimeFormat(pattern = "yyyy-MM-dd") Date start, @RequestParam(value = "end") @DateTimeFormat(pattern = "yyyy-MM-dd") Date end, @RequestParam(value = "industry", required = false) String industry) throws ParseException {
		return zs.queryCustomerSattackByProvinceAndIndustry(pn, ps, SDF.format(start), SDF.format(end), null, industry,"industry");
	}

	/**
	 * 3.监控监测 受攻击趋势及统计 受攻击趋势折线图 地址:/as/sgjqsjtj/line/sgjqs 参数:{
	 * start:'2015-1-1', end:'2015-1-1', province:'xx', industry:'xx' } 返回: [ {
	 * "name":'xxx', "score":123 }, { "name":'xxx', "score":123 } ]
	 * 
	 * @param start
	 * @param end
	 * @param province
	 * @param industry
	 * @return
	 * @throws ParseException
	 */
	@ResponseBody
	@RequestMapping(value = "sgjqsjtj/line/sgjqs", produces = "application/json; charset=utf-8")
	public String sgjqs(@RequestParam(value = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date start, @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date end, @RequestParam(value = "province", required = false) String province, @RequestParam(value = "industry", required = false) String industry) throws ParseException {
		return zs.getattackTrend(SDF.format(start), SDF.format(end), province, industry);
	}

	/**
	 * 监控监测 受攻击趋势及统计 攻击源排名 地址:/as/sgjqsjtj/line/gjypm 参数:{ start:'2015-1-1',
	 * end:'2015-1-1', province:'xx', industry:'xx' } 返回: [ { "name":'xxx',
	 * "score":123 }, { "name":'xxx', "score":123 } ]
	 * 
	 * @param pn
	 * @param ps
	 * @param start
	 * @param end
	 * @param province
	 * @param industry
	 * @return
	 * @throws ParseException
	 */
	@ResponseBody
	@RequestMapping(value = "sgjqsjtj/line/gjypm", produces = "application/json; charset=utf-8")
	public String attackSourceRanking(@RequestParam(value = "pn", required = false, defaultValue = "1") int pn, @RequestParam(value = "ps", required = false, defaultValue = "20") int ps, @RequestParam(value = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date start, @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date end, @RequestParam(value = "province", required = false) String province, @RequestParam(value = "industry", required = false) String industry) throws ParseException {
		return zs.getAttackSourceRanking(pn, ps, SDF.format(start), SDF.format(end), province, industry);
	}

	/**
	 * 监控监测 受攻击详情 地址:/as/sgjdetail 参数:{ start:'2015-1-1', end:'2015-1-1',
	 * customerid:'xxx' } 返回: { "data":[ source_ip:'xxx', //攻击源ip 'type':xxx
	 * //事件类型 url:xx //设备名 score:'' //事件总数 根据前三项分组统计得出 danger_level:危险等级 ] }
	 * 
	 * @param start
	 * @param end
	 * @param type
	 * @param customers
	 * @return
	 * @throws ParseException
	 */
	@ResponseBody
	@RequestMapping(value = "sgjdetail/{type}", produces = "application/json; charset=utf-8")
	public String attackDetails(@RequestParam(value = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date start, @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date end, @PathVariable(value = "type") String type, @RequestParam(value = "customer", required = false) String customer) throws ParseException {
		return zs.getAttackDetails(SDF.format(start), SDF.format(end), type, customer);
	}
}
